<template>
  <div>
    <div class="date-box">
      <DatePicker></DatePicker>
    </div>
    <div class="area-box">
      <div>
        <AreaSelect>
          <template class="province" v-slot:province>请选择省:</template>
          <template v-slot:city>请选择市:</template>
          <template v-slot:area>请选择区：</template>
        </AreaSelect>
      </div>
      <button @click="screendatas">筛选</button>
    </div>
    <div class="data-box">
      <div class="data-item">
        <h4 class="title">成交用户数量</h4>
        <div>{{ strikeNum }}人</div>
      </div>
      <div class="data-item">
        <h4 class="title">用户注册统计</h4>
        <div>{{ loginNum }}人</div>
      </div>
      <div class="data-item">
        <h4 class="title">销售统计</h4>
        <div>{{ saleNum }}张</div>
      </div>
    </div>
  </div>
</template>

<script>
import { datasrequest, getScreenData } from "../../api/datas";
import { Bus } from "../../Bus";
import AreaSelect from "../../components/sales/areaSelect";
import DatePicker from "../../components/sales/DatePicker";
export default {
  components: {
    AreaSelect,
    DatePicker,
  },
  data() {
    return {
      obj: {
        province: "",
        city: "",
        area: "",
      },
      stime: "",
      etime: "",
      isShow: true,
      strikeNum: "",
      loginNum: "",
      saleNum: "",
    };
  },
  mounted() {
    Bus.$emit("isshowcity", this.isShow);
    Bus.$emit("isshowarea", this.isShow);
    datasrequest({}).then((res) => {
      this.strikeNum = res.data.res2;
      this.loginNum = res.data.korder;
      this.saleNum = res.data.res;
    });
    Bus.$on("areadatas", (value) => {
      this.obj = value;
    });
    Bus.$on("stime", (value) => {
      this.stime = value;
    });
    Bus.$on("etime", (value) => {
      this.etime = value;
    });
  },
  created() {},
  methods: {
    screendatas() {
      let datas = {};
      let create_time = {};
      if (this.obj.province.length != 0 && this.obj.province != "全部省"){
        datas.province = this.obj.province;
      }
      if (this.obj.city.length != 0 && this.obj.city != "全部市") {
        datas.city = this.obj.city;
      }
      if (this.obj.area.length != 0 && this.obj.area != "全部区") {
        datas.area = this.obj.area;
      }
      if(this.stime !="" && this.etime !=""){
        create_time.startTime = this.stime;
        create_time.enterTime = this.etime;
      }
      getScreenData({ datas},{create_time}).then((res) => {
        this.strikeNum = res.data.order;
        this.loginNum = res.data.res;
        this.saleNum = res.data.userNum;
      });
    },
  },
};
</script>
<style lang="less" scoped>
.date-box,
.data-box {
  margin: 30px;
}
.area-box {
  margin-left: 15px;
  display: flex;
  height: 40px;
  align-items: center;
}
button {
  width: 70px;
  height: 40px;
}
.data-box {
  width: inherit;
  display: flex;
}
.data-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-right: 20px;
  width: 250px;
  height: 80px;
  background-color: #fff;
  border-radius: 5px;
  text-align: left;
  padding-left: 20px;
  box-sizing: border-box;
}
.data-item:hover {
  box-shadow: 1px 2px 6px 2px #d4cdcd;
}
.title {
  padding: 0px;
  margin: 0px;
  margin-bottom: 10px;
  font-weight: 600;
}
</style>